#include "mq_connection.hpp"

int main()
{
    mq::AsyncWorker::ptr worker_ptr=std::make_shared<mq::AsyncWorker>();
    mq::Connection::ptr connection_ptr=std::make_shared<mq::Connection>("127.0.0.1",8080,worker_ptr);
    //1.创建信道
    mq::Channel::ptr channel=connection_ptr->openChannel();
    //2.声明交换机,交换机类型是广播模式
    google::protobuf::Map<std::string,std::string> tmp_map;
    channel->declareExchange("exchange1",mq::ExchangeType::TOPIC,true,false,tmp_map);
    channel->declareQueue("queue1",true,false,false,tmp_map);
    channel->declareQueue("queue2",true,false,false,tmp_map);
    channel->queueBind("exchange1","queue1","queue1");
    channel->queueBind("exchange1","queue2","new.music.#");
    //3.发布消息
    for(int i=0;i<5;i++)
    {
        mq::BasicProperties bp;
        bp.set_id(mq::UUIDHelper::uuid());
        bp.set_delivery_mode(mq::DeliveryMode::DURABLE);
        bp.set_routing_key("new.music.pop");
        //bp.set_routing_key("queue1");
        channel->basicPublish("exchange1",&bp,"hello world-"+std::to_string(i));
        DLOG("信息发送成功");
    }
    connection_ptr->closeChannel(channel);
    return 0;
}